package com.example.behaviordemo.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.behaviordemo.R
import com.example.behaviordemo.adapter.SpecialColumnAdapter
import com.example.behaviordemo.model.SpecialColumn

/**
 * author : king_nina
 * e-mail : 13450414852@163.com
 * date   : 2021/12/2
 * desc   :
 */
class SpecialColumnFragment : Fragment() {

    private lateinit var rootView: View
    private lateinit var recyclerView: RecyclerView
    private lateinit var specialColumnAdapter: SpecialColumnAdapter

    companion object {
        fun newInstance(): SpecialColumnFragment {
            val fragment = SpecialColumnFragment()
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        rootView = inflater.inflate(R.layout.fragment_special_column, container, false)
        initView()
        return rootView
    }

    private fun initView() {
        recyclerView = rootView.findViewById(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(context)
        val specialColumn = SpecialColumn(
            "Android",
            100, 100
        )
        recyclerView.addItemDecoration(
            DividerItemDecoration(
                activity, LinearLayoutManager.HORIZONTAL
            )
        )
        val specialColumns = mutableListOf<SpecialColumn>()
        specialColumns.add(specialColumn)
        specialColumns.add(specialColumn)
        specialColumns.add(specialColumn)
        specialColumnAdapter = SpecialColumnAdapter(specialColumns)
        recyclerView.adapter = specialColumnAdapter
    }
}